package com.coocaa.ops.plus.dashboard.third.internalapi;

import com.coocaa.ops.common.core.base.model.R;
import com.coocaa.ops.common.core.biz.cache.yml.CacheUpdateProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.URI;
import java.net.URISyntaxException;

/**
 * @author bjh
 * @description
 * @date 2021/2/3 14:47
 */
@Service
public class InternalApiFeignClientService {
    @Autowired
    private InternalApiFeignClient internalApiFeignClient;
    @Autowired
    private CacheUpdateProperties cacheUpdateProperties;


    public R listKeyType() {
        try {
            return internalApiFeignClient.listKeyType(new URI(cacheUpdateProperties.getDashboard()));
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return R.fail("request error");
        }
    }


    public R listKey(String key, String cacheEnv, Integer page, Integer pageSize, Integer match) {
        try {
            return internalApiFeignClient.listKey(new URI(cacheUpdateProperties.getDashboard()), key,cacheEnv, page, pageSize, match);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return R.fail("request error");
        }
    }


    public R getValByKey(String key, String cacheEnv) {
        try {
            return internalApiFeignClient.getValByKey(new URI(cacheUpdateProperties.getDashboard()), key, cacheEnv);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return R.fail("request error");
        }
    }


    public R delByKey(String[] keys, String cacheEnv,String sign, Integer match) {
        try {
            return internalApiFeignClient.delByKey(new URI(cacheUpdateProperties.getDashboard()), keys,cacheEnv, sign, match);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return R.fail("request error");
        }
    }


    public R ttl(String key,String cacheEnv) {
        try {
            return internalApiFeignClient.ttl(new URI(cacheUpdateProperties.getDashboard()), key, cacheEnv);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return R.fail("request error");
        }
    }


    public R getSwitcherInfo(String type) {
        try {
            return internalApiFeignClient.getSwitcherInfo(new URI(cacheUpdateProperties.getDashboard()), type);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return R.fail("request error");
        }
    }


    public R getAllSwitcher() {
        try {
            return internalApiFeignClient.getAllSwitcher(new URI(cacheUpdateProperties.getDashboard()));
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return R.fail("request error");
        }
    }
}
